<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>简报</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<input type="hidden" id="id" name="id" th:value="${id}">
<input type="hidden" id="companyName" name="companyName">
<div class="container-fluid">
    <div class="row" th:class="text-center" style="margin-top: 20px;">
        <h4 th:class="text-left" th:id="title"></h4>
        <p th:class="text-left" th:id="content"></p>
        <p th:class="text-left">关联公司：<a href="#" id="shipCompany" target="_blank"></a></p>
        <p th:class="text-left">情报源：<span id="infoSource"></span></p>
        <p><a class="btn btn-secondary" href="#" role="button" id="sourceUrl" target="_blank">查看原文</a></p>
    </div>

    <div class="my-3 p-3 bg-white rounded shadow-sm">
        <h6 class="border-bottom border-gray pb-2 mb-0">其它情报</h6>
        <div id="list">

        </div>
        <small class="d-block text-right mt-3">
            <a href="#" id="more">更多>></a>
        </small>
    </div>
</div>
</body>

<script type="text/javascript">

    var page = 1;
    var pagesize = 10;

    $(function(){
        var id = $("#id").val();
        loadArticle(id);
        loadData(page, pagesize);
        $("#more").attr("href", "/custom/core/news/articles?companyName=" + $("#companyName").val())
    });

    function loadArticle(id){
        $.ajax({
            url:"/custom/core/news/article?id="+id,
            type:"json",
            method:"post",
            async:false,
            success:function(resp) {
                var title = resp.title;
                if (title == null) {
                    title = resp.source;
                }
                $("#title").html(title);
                $("#content").html(resp.content);
                $("#sourceUrl").attr("href", resp.sourceUrl);
                $("#companyName").val(resp.name);
                $("#shipCompany").html(resp.shortName)
                $("#infoSource").html(resp.dataSource)
                $("#shipCompany").attr("href", "/custom/core/company/company_detail?name=" + resp.name)
            }
        });
    }

    function loadData(page, pagesize) {
        $.ajax({
            url:"/custom/core/news/pageAjax?curPage="+page+"&pagesize=" + pagesize + "&companyName=" + $("#companyName").val(),
            type:"json",
            method:"post",
            async:false,
            success:function(resp) {
                var list = resp.records;
                for (var i = 0; i < list.length; i++) {
                    var item = list[i];
                    if (item.id == $("#id").val()) {
                        continue
                    }
                    var title = item.title;
                    if (title == null) {
                        title = item.source;
                    }
                    var html = '<div className="media text-muted pt-3">'
                    html += '<a className="media-body pb-3 mb-0 small lh-125 border-bottom border-gray" href="/custom/core/news/article_detail?id='+item.id+'">';
                    html += title;
                    html += '</a>';
                    html += '</div>'
                    $("#list").append(html);
                }
            }
        });
    }
</script>
</html>